package com.daisuxia.attach.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.daisuxia.attach.pojo.UserInfoTude;
import com.daisuxia.attach.service.IUserInfoTudeService;
import com.daisuxia.back.utils.RequestUtils;
import com.daisuxia.back.utils.ServiceResult;
import com.daisuxia.back.utils.SpringUtils;
import com.daisuxia.back.utils.SysCacheUtils;
import com.daisuxia.web.controller.BaseController;
import com.daisuxia.web.controller.UserLoginController;
import com.daisuxia.web.pojo.*;
import com.daisuxia.web.service.*;
import com.daisuxia.web.util.JSONUtil;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

@Controller
public class VersionsManagersController {
	
	@Autowired
	private BackConfigParamsService backConfigParamsService;
	
	/**
	 * @param request
	 * @param response
	 * @param model
	 */
	@RequestMapping(value="versionsManagers/getVersionsInfo")
	public void getVersionsInfo(HttpServletRequest request,HttpServletResponse response, Model model){
		Map<String, Object> dataMap=new HashMap<String, Object>();
		Map<String, Object> resultMap=new HashMap<String, Object>();
		JSONObject jsonObj = new JSONObject();
		String code="-1";
		String msg="";
		try {
			String appVersion = request.getParameter("appVersion")==null?"": request.getParameter("appVersion");//app版本号  2.2.0
			String[] str = appVersion.split("\\.");
			String v = "";
			if (str[0].toLowerCase().indexOf("V")!=-1) {
				v = str[0].substring(1, str[0].length()-1);
			}else{
				v = str[0];
			}

			//0、不提示更新  1、提示更新 2、强制更新
			int verNum=Integer.parseInt(v)*100+Integer.parseInt(str[1])*10+Integer.parseInt(str[2]);
			if(false){
				resultMap.put("whether_need_upgrade", 1);
				resultMap.put("update_context", "");
				msg="提示更新";
			}else{
				resultMap.put("whether_need_upgrade", 0);
				resultMap.put("update_context", "");
				msg="不提示更新";
			}
			code = "0";
		} catch (Exception e) {
			e.printStackTrace();
			code = "500";
			msg = "系统异常";;
		}finally{
			dataMap.put("item", resultMap);
			jsonObj.put("code",code);
			jsonObj.put("message",msg);
			jsonObj.put("data",dataMap);
			JSONUtil.toObjectJson(response, jsonObj.toString());
		}
	}
}
